#include <bits/stdc++.h>
using namespace std;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using ll = long long;
void solve()
{
    ll n, k;
    vector<ll> a;
    cin >> n >> k;
    a.resize(n, 0);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll ans = 0;
    sort(a.begin(), a.end());
    for (ll i = 0; i < n; i++)
    {

        if (k == 0)
        {
            break;
        }
        else
        {
            // n+n-1+...+2
            // a1==a[i]  d= -1
            // (a[i]-1)== n    
            //  n-1
            // n -> a[i]
            //  n-1
            if (k >= a[i] )
            {
                ans += (a[i] ) * a[i] - (a[i]) * (a[i]-1 ) / 2;
                k -= a[i] ;
            }
            else
            {
                ans += (k)*a[i] - (k) * (k - 1) / 2;
                k = 0;
            }
        }
    }
    cout << ans;
}
int main()
{
    int t = 1;
    // cin >> t;
    while (t--)
    {
        //cout << (4 - 1) *4 - (4 - 1) * (4 - 2) / 2;
        solve();
    }
    return 0;
}
